var mongoose = require("mongoose");
var db = require("./db.js");

var bookSchema = new mongoose.Schema({       // Schema 结构
    name    : {type : String},
    author  : {type : String},
    price   : {type : Number},
});

bookSchema.statics.Findbook = function(callback){       // 找到所有图书
    this.model("Book").find({}, callback);
}

bookSchema.statics.FindbookByName = function(name,callback){       // 根据id查找图书
    this.model("Book").find({"name": name}, callback);
}

var bookModel = db.model('Book',bookSchema); // Student模型,基于schema创建

module.exports = bookModel